import axios from "../plugin/http";

export default {
  getSystems(cb, errorCb) {
    axios
      .get(`/api/system/`)
      .then(result => {
        cb(result.data);
      })
      .catch(err => {
        errorCb(err);
      });
  },
  updateSystem(payload, cb, errorCb) {
    // debugger;
    axios
      .put(`/api/system/${payload._id}/`, {
        "header": {
          "sysCode": "IDS",
          "platform": window.navigator.platform,
          "timestamp": new Date().getTime()
        },
        "payload": {
          "sysName": payload.sysName
        }
      })
      .then(result => {
        cb(result.data);
      })
      .catch(err => {
        errorCb(err);
      });
  },
  insertSystem(payload, cb, errorCb) {
    axios
      .post(`/api/system/`, {
        "header": {
          "sysCode": "IDS",
          "platform": window.navigator.platform,
          "timestamp": new Date().getTime()
        },
        payload
      })
      .then(result => {
        cb(result.data);
      })
      .catch(err => {
        errorCb(err);
      });
  },
  deleteSystem(payload, cb, errorCb) {
    axios
      .delete(`/api/system/${payload._id}`, {
        "header": {
          "sysCode": "IDS",
          "platform": window.navigator.platform,
          "timestamp": new Date().getTime()
        },
      })
      .then(result => {
        cb(result.data);
      })
      .catch(err => {
        errorCb(err);
      });
  }
}
